/* @(#)GSBusOrderDetailDAO.java    
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li     2006-2-15    新增
 *   Simonyi Peng 2006-3-21  add queryOrderDetailByDetailId,queryOrderDetail_方法
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.dao;

import java.util.ArrayList;

import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSBusOrderManufactureVO_;
import com.hitrust.gs.vo.GSOrderMan4QueryVO;

/**
 * 
 */
public class GSBusOrderDetailDAO  extends GSBaseDAO {
    /**
     * 根据订单编号查询订单所订的全部产品信息
     * @param aOrderId              
     * @return
     * @throws GSException
     */
    public ArrayList queryOrderDetail(String aOrderId) throws GSException{
        
        ArrayList tList = new ArrayList();
        
        StringBuffer tSql = new StringBuffer("select b.GS_MANUFACTURE_ID as P1,b.GS_MANUFACTURE_NAME as P2,");
            tSql.append("b.GS_MANUFACTURE_UNITPRICE as P3,a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
            tSql.append("c.GS_ORG_NAME as P7,a.GS_DELIVER_GOODS_ADDR as P8,a.GS_ORDER_CONTACT_NAME as P9,a.GS_ORDER_CONTACT_PHONE as P10,");
            tSql.append("a.GS_DELIVER_MODE as P11,a.GS_BALANCE_MODE as P12,d.GS_PROVIDER_NAME as P13, a.GS_ORDER_TEMPID as P14,");
            tSql.append("a.GS_ORDER_DETAIL_ID as P15,a.GS_ORDER_DETAIL_NOTE as P16,a.GS_ORDER_DETAIL_STATUS as P17,b.GS_IS_TRADEFLAT_MANUFACTURE as P18,b.GS_QUANT_UNIT as P19");
            tSql.append(",a.GS_CONCENTRICITY_ID as P20 ");
            tSql.append(" from GS_ORDER_DETAIL a,GS_MANUFACTURE b,GS_ORGANIZATION c,GS_PROVIDER d ");
            tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID and a.GS_ORDER_DEPT_ID=c.GS_ORG_ID and d.GS_PROVIDER_ID=a.GS_PROVIDER_ID");
        Object[] tObj = {aOrderId};
        try{
            tList = executeQuery(new GSOrderMan4QueryVO(),tSql.toString(),tObj);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }
        return tList;
    }
    
    /**
     * 查询订单详细信息,查询订单明细包括单价
     * @param aOrderId
     * @return
     * @throws GSException
     */
    public GSBusOrderManufactureVO_ queryOrderDetailByDetailId(String aDetailId) throws GSException {
        GSBusOrderManufactureVO_ vo = null;
        
        StringBuffer tSql = new StringBuffer("select b.APEP_CODE as P1,b.NAME as P2,a.GS_CONCENTRICITY_ID as P3,");
            tSql.append("a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
            tSql.append("b.SPEC as P7,b.MODEL as P8,b.PRODUCT_BRAND as P9,");
            tSql.append("b.PRODUCT_UNIT as P10,b.UNIT_PRICE as P11,b.QUALITY_ASSURE_PERIOD as P12,");
            tSql.append("a.GS_ORDER_DETAIL_ID as P13,a.GS_ORDER_TEMPID as P14,a.GS_BALANCE_CATEGORY_NO as P15,a.gs_balance_mode as P16 ");
            tSql.append("from GS_ORDER_DETAIL a,t_product b ");
            tSql.append("where a.GS_ORDER_DETAIL_ID=? and a.GS_MANUFACTURE_ID= b.APEP_CODE  ");
        Object[] tObj = {aDetailId};
        try{
            ArrayList tList = executeQuery(new GSBusOrderManufactureVO_(),tSql.toString(),tObj);
            if(tList!=null)
                vo = (GSBusOrderManufactureVO_)tList.get(0);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }

        return vo;
        
    }

    /**
     * 查询订单详细信息,查询订单明细包括单价
     * @param aOrderId
     * @return
     * @throws GSException
     */
    public ArrayList queryOrderDetail_(String aOrderId) throws GSException {
        GSBusOrderManufactureVO_ vo = null;
        ArrayList tList = new ArrayList();
        
        StringBuffer tSql = new StringBuffer("select b.GS_MANUFACTURE_ID as P1,b.GS_MANUFACTURE_NAME as P2,a.GS_CONCENTRICITY_ID as P3,");
            tSql.append("a.GS_ORDER_COUNT as P4,a.GS_DELIVER_GOODS_DATE as P5,a.GS_DELIVER_GOODS_TIME as P6,");
            tSql.append("b.GS_MANUFACTURE_SPEC as P7,b.GS_MANUFACTURE_TYPE as P8,b.GS_MANUFACTURE_BRAND as P9,");
            tSql.append("b.GS_QUANT_UNIT as P10,b.GS_MANUFACTURE_UNITPRICE as P11,b.GS_QUALITY_ASSURE_PERIOD as P12,");
            tSql.append("a.GS_ORDER_DETAIL_ID as P13,a.GS_ORDER_TEMPID as P14,a.GS_BALANCE_CATEGORY_NO as P15,a.gs_balance_mode as P16 ");
            tSql.append("from GS_ORDER_DETAIL a,GS_MANUFACTURE b ");
            tSql.append("where a.GS_ORDER_TEMPID=? and a.GS_MANUFACTURE_ID= b.GS_MANUFACTURE_ID  ");
        Object[] tObj = {aOrderId};
        try{
            tList = executeQuery(new GSBusOrderManufactureVO_(),tSql.toString(),tObj);
        }catch(Exception e){
            GSLogWriter.error(this,e.toString());
            throw new GSException(GSException.E19999,GSException.E19999_MSG);
        }

        return tList;
        
    }

}
